package com.dailyblue.java.project.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dailyblue.java.project.bookstore.bean.Category;
import com.dailyblue.java.project.bookstore.mapper.CategoryMapper;
import com.dailyblue.java.project.bookstore.service.CategoryService;
import com.dailyblue.java.project.bookstore.util.JsonResult;
import com.dailyblue.java.project.bookstore.util.ResultTool;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Cacheable(cacheNames = "categoryFind", key = "0")
    public JsonResult find() {
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        wrapper.eq("state", "1");
        wrapper.orderByAsc("sort");
        List<Category> categorys = list(wrapper);
        return ResultTool.success(categorys);
    }
}
